package com.cs.framework.jdbc.aop;

import java.util.Date;

import org.aspectj.lang.JoinPoint;

import com.cs.framework.common.bo.BoBase;
import com.cs.framework.common.util.DateUtils;
import com.cs.framework.web.handler.Web;

/**
 * 业务对象Dao处理
 * 
 * @author hedongzhou
 * 
 */
public class BoBaseDaoAop {

	/**
	 * 保存实体前处理
	 * 
	 * @param jp
	 */
	public void beforeSave(JoinPoint jp) {
		Object entity = jp.getArgs()[0];

		if (entity instanceof BoBase) {
			BoBase bo = (BoBase) entity;
			Date date = DateUtils.getCurrentDate();
			String userId = Web.getUserId();

			bo.setValid("Y");
			bo.setCreateUser(userId);
			bo.setCreateDate(date);
			bo.setUpdateUser(userId);
			bo.setUpdateDate(date);
		}
	}

	/**
	 * 更新实体前处理
	 * 
	 * @param jp
	 */
	public void beforeUpdate(JoinPoint jp) {
		Object entity = jp.getArgs()[jp.getArgs().length - 1];

		if (entity instanceof BoBase) {
			BoBase bo = (BoBase) entity;
			Date date = DateUtils.getCurrentDate();
			String userId = Web.getUserId();

			bo.setUpdateUser(userId);
			bo.setUpdateDate(date);
		}
	}

}
